const {
  $util,
} = getApp();
Page({
  data: {
    list: [],
    page: 1,
    hasMore: true,
    loaded: false,
  },
  onLoad(opts) {
    this.loadList();
  },
  loadList() {
    const {
      page,
      list: d_list,
    } = this.data;
    $util.request({
      url: 'entry/wxapp/partyman.integral.getmypoints',
      data: {
        page,
      },
      success: (res) => {
        let list = res.data;
        if (page > 1) {
          list = [...d_list, ...list];
        }
        this.setData({
          list,
          hasMore: list.length < res.total,
          loaded: true,
        });
      },
    });
  },
  onReachBottom() {
    if (!this.data.hasMore) return;
    this.setData({
      page: this.data.page + 1,
    }, () => {
      this.loadList();
    });
  },
});
